﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enterprise.Framework.Frame.Architecture;
using Resto.CostControl.Core.Query.SiteModule.ViewObject;
using Enterprise.Framework.DomainModel.Repositories;
using Resto.CostControl.Core.Domain.Model;
using Enterprise.Framework.DomainModel.Specifications;
using Enterprise.Framework.DomainModel;

namespace Resto.CostControl.Core.Query.SiteModule.QueryObject
{
    public class SiteQO : IApplicationQueryObject
    {
        private IQueryable<SiteVO> GetSiteVOSet()
        {
            IEntityRepository<Site> repository = RestoCostDomainSession.CurrentSession.CreateEntityRepository<Site>();

            IQueryable<SiteVO> list = from o in repository.Objects
                                      where o.IsDelete == false
                                      select new SiteVO()
                                      {
                                          ID = o.ID,
                                          Code = o.Code,
                                          Name = o.Name,
                                          SiteAddress = o.SiteAddress,
                                          DeliveryAddress = o.DeliveryAddress,
                                          PMName = o.PMName,
                                          ChefsName = o.ChefsName,
                                          AreaCode = o.AreaCode,
                                      };

            return list;
        }

        public SiteVO[] QuerySiteVOByPager(ISpecification<SiteVO> spec, PagerCondition pager, string orderKey, bool isAscending)
        {
            IQueryable<SiteVO> list = GetSiteVOSet();

            if (spec != null)
                list = list.Where(spec.GetExpression());

            IEnumerable<SiteVO> list2 = RepositoryExtention.Query(list, pager, orderKey, isAscending);
            return list2.ToArray();
        }
    }
}
